What is $digest and $apply?
What is $digest and
$apply? explain with example.
Ravi Vishwakarma is a dedicated Software Developer with a passion for crafting efficient and innovative solutions. With a keen eye for detail and years of experience, he excels in developing robust software systems that meet client needs. His expertise spans across multiple programming languages and technologies, making him a valuable asset in any software development project.
Richal Singh
12-Feb-2026In AngularJS (1.x),
$digestand$applyare core methods used for change detection and synchronizing the model (scope) with the view (HTML).$digest
$digest()runs the digest cycle, where Angular checks all registered watchers and updates the DOM if model values have changed.It processes the current scope and its child scopes.
It does not evaluate expressions globally.
Angular automatically calls
$digest()during built-in events likeng-click,ng-model,$http, etc.Example:
Normally, you don’t call
$digest()directly unless you know what you’re doing.$apply
$apply()is used when code runs outside Angular’s context (e.g.,setTimeout, third-party JS). It executes your function and then automatically triggers a$digest()cycle.Example:
Here:
$apply()runs the function.Then Angular internally calls
$digest()to update the view.Difference (Programming View)
$digest()→ Performs change detection.$apply()→ Executes external code + triggers$digest()automatically.In short, use
$apply()when updating scope outside Angular;$digest()is the internal mechanism that updates bindings.